//
//  HZDiseaseCollView.m
//  MyDoctor
//
//  Created by 黑眼圈 on 16/5/4.
//  Copyright © 2016年 heiyan. All rights reserved.
//

#import "HZDiseaseCollView.h"


@interface HZDiseaseCollView()<UICollectionViewDataSource,UICollectionViewDelegate>

@property(nonatomic,strong)NSArray*  array;

@end

@implementation HZDiseaseCollView




-(instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout{
    
    if (self = [super initWithFrame:frame collectionViewLayout:layout]) {
        
        //设置并添加子控件
        [self setupUI];
        
        
    }
   
    return self;
}


#pragma mark -
#pragma mark    设置并添加子控件
-(void)setupUI{
   
    //设置数据源和代理
    self.delegate = self;
    self.dataSource = self;
    
    //注册 cell
    [self registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"disease"];
    [self registerClass:[HZDiseaseCell class] forCellWithReuseIdentifier:@"hzdisease"];
    
    //获取布局对象
    UICollectionViewFlowLayout* flow = (UICollectionViewFlowLayout*)self.collectionViewLayout;
  
    //设置cell的间隙
    flow.minimumInteritemSpacing = 0;
    flow.minimumLineSpacing = 0;
    
}

#pragma mark -
#pragma mark     懒加载数据的数组
-(NSArray *)array{
    if (!_array) {
        
        _array = [HZDiseaseModel getdiseaseArray];
    }
    
    return _array;
}


#pragma mark -
#pragma mark     CollectionView的数据源代理方法
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 7;
}

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    //取得 cell
    if (indexPath.row == 0) {
        
        UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"disease" forIndexPath:indexPath];
        
        //创建名医通标题
        HZHeadlineView* headlineView = [[HZHeadlineView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 40)];
        
        //添加标题到 cell 上面
        [cell addSubview:headlineView];
       
        //设置边界
        cell.layer.borderWidth = 0.5;
        cell.layer.borderColor = [UIColor colorWithRed:170/255.0 green:170/255.0 blue:170/255.0 alpha:1].CGColor;

        return cell;
        
    } else {
        
        //取出对应的数据
        HZDiseaseModel* model = self.array[indexPath.row-1];
        
        //取出自定义的 cell
        HZDiseaseCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"hzdisease" forIndexPath:indexPath];
 
        //赋值
        cell.model = model;
  
        //返回
        return cell;
    }
    
    

}


#pragma mark -
#pragma mark     返回不同 cell 的尺寸
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        
        return CGSizeMake(SCREENW, 40);
    }
    
    int weight = (SCREENW)/3;
    int hight = (self.bounds.size.height-40)/2;
    
    return CGSizeMake(weight, hight);
}







#pragma mark -
#pragma mark     懒加载子控件






@end
